package edu.pku.sei.transformation.editor.controller.commands.node;

import org.eclipse.gef.commands.Command;

import edu.pku.sei.transformation.editor.model.execution.AtomicTransformationExecution;
import edu.pku.sei.transformation.editor.model.execution.RuleExecution;

public class RuleExecutionDeleteCommand extends Command {
	private RuleExecution ruleExe;
	private AtomicTransformationExecution transExe;
	int index = 0;

	public RuleExecutionDeleteCommand(RuleExecution child,
			AtomicTransformationExecution father) {
		this.ruleExe = child;
		this.transExe = father;
	}

	@Override
	public boolean canExecute() {
		if (ruleExe == null || transExe == null)
			return false;
		else
			return true;
	}

	@Override
	public void execute() {
		index = transExe.getSpecifiedRules().indexOf(ruleExe);
		transExe.getSpecifiedRules().remove(ruleExe);
		ruleExe.setContext(null);
	}

	@Override
	public void undo() {
		ruleExe.setContext(transExe);
		transExe.getSpecifiedRules().add(index, ruleExe);
	}
}
